package com.graduation.clientback.config;

import com.graduation.clientback.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Value("${graduation.profile}")
    private String profile;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录和注册接口不拦截
        registry.addInterceptor(loginInterceptor).excludePathPatterns("/tbUser/login", "/profile/**");
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // addResourceHandler为对/img开头的请求进行静态资源访问处理
        // addResourceLocations为设置静态资源的访问路径
        registry.addResourceHandler("/profile/upload/**").addResourceLocations("file:" + profile + "/");
    }
}
